using System;
using System.Collections.Generic;

namespace Glue.Internals.PrintTool
{
    internal class RelationReport
    {
        public String LeftTypeName { get; private set; }
        public string RightTypeName { get; private set; }
        public int LeftColumnSize { get; private set; }
        public int RightColumnSize { get; private set; }

        public RelationReport(Type leftType, Type rightType)
        {
            LeftTypeName = leftType.Name;
            RightTypeName = rightType.Name;
            LeftColumnSize = LeftTypeName.Length;
            RightColumnSize = RightTypeName.Length;

        }
        private List<ReportLine> lines = new List<ReportLine>();

        public IEnumerable<ReportLine> GetLines()
        {
            return lines;
        }

        public void SortOnLeftColumn()
        {
            lines.Sort((x, y) => string.Compare(x.LeftSidePropertyName, y.LeftSidePropertyName));
        }

        public void SortOnRightColumn()
        {
            lines.Sort((x, y) => string.Compare(x.RightSidePropertyName, y.RightSidePropertyName));
        }

        public void AddLine(ReportLine reportLine)
        {
            var leftLength = reportLine.LeftSidePropertyName.Length;
            if (leftLength > LeftColumnSize) LeftColumnSize = leftLength;
            var rightLength = reportLine.RightSidePropertyName.Length;
            if (rightLength > RightColumnSize) RightColumnSize = rightLength;
            lines.Add(reportLine);
        }
    }
}